# -*- coding: utf-8 -*-
# +
import pandas as pd 
import numpy as np 
import sys,os
from datetime import datetime

from config import CONFIG
from functions import *


# +
def nomalize(df, features):
    for fea in features:
        df[fea] = (df[fea] - df[fea].mean()) / df[fea].std()
    return df

def run_one_encode(tar):
    print(tar)
    file_path = os.path.join(CONFIG().MERGED_DATASET_PATH, tar)
    df = pd.read_csv(file_path)
    # 处理风向
    df['WIND_DIR'] = df['WIND_DIR'] * np.cos(df['WIND_DIR'] * np.pi / 180)
    # 归一化特征
    features = [i for i in list(df) if i in CONFIG().FEATURES]
    for fea in features:
        df[fea] = (df[fea] - df[fea].mean()) / df[fea].std()
    df.to_csv(os.path.join(CONFIG().MERGED_DATASET_PATH_ZSCORE, tar))
    # 进一步归一化label
    labels = CONFIG().LABELS
    for fea in labels:
        df[fea] = (df[fea] - df[fea].mean()) / df[fea].std()
    df.to_csv(os.path.join(CONFIG().MERGED_DATASET_PATH_ZSCORE2, tar))
def basic_feature_encode():
    targets = [i for i in os.listdir(CONFIG().MERGED_DATASET_PATH) if 'SCD' not in i]
    pool(run_one_encode, [(tar,) for tar in targets])
    print('all ok.')


# -

basic_feature_encode()
